<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tìm kiếm</title>
<script type="text/javascript" src="java/kiemtratim.js"></script>
<script>
function validForm(){
var ten = document.getElementById('ten');
var filter = /[a-zA-Z0-9]/;
if(!filter.test(ten.value)){
document.tim.ten.focus();
return false;
}
}

</script>

<script>
function validForm_search_1(){
	if (document.search_form_1.gia_tu.selectedIndex=="0") {
			alert("Quý khách chưa chọn giá từ");
			document.search_form_1.gia_tu.focus();
			return false;
		}
	if (document.search_form_1.gia_den.selectedIndex=="0") {
			alert("Quý khách chưa chọn giá đến");
			document.search_form_1.gia_den.focus();
			return false;
		}
	if (document.search_form_1.gia_tu.selectedIndex > document.search_form_1.gia_den.selectedIndex) {
			alert("Quý khách chưa chọn giá đến phải lớn hơn giá từ");
			document.search_form_1.gia_den.focus();
			return false;
		}		
}
</script>


</head>

<body>
<?php
include("kn.php");
if(!isset($_GET["gia_tu"])&&!isset($_GET["gia_den"]))
{
$gia_tu = $_POST["gia_tu"];
$gia_den= $_POST["gia_den"];
}
else
{
$gia_tu = $_GET["gia_tu"];
$gia_den = $_GET["gia_den"];
}
$lenh = "select hinh,tenlaptop,tenhanglaptop,tenloai,concat(soluong,' Cái') as soluong,concat(format(dongia,0),' VNĐ') as dongia,mota from laptop,hanglaptop,loailaptop where laptop.mahanglaptop = hanglaptop.mahanglaptop and laptop.maloailaptop = loailaptop.maloailaptop and laptop.Dongia >= ".$gia_tu." and laptop.Dongia <= ".$gia_den."";
$kq = mysql_query($lenh);
$n = mysql_num_rows($kq);
if($n >0)
{
$tb = "Tím thấy ".$n." laptop";
}
else
{
$tb = "Không tìm thấy laptop nào!";

}
$sodong = 4;
$sotrang = ceil($n/$sodong);
if(!$_GET["p"])
$p = 1;
else
$p = $_GET["p"];
$x = ($p -1)*$sodong;

$lenh1 = "select hinh,tenlaptop,tenhanglaptop,tenloai,concat(soluong,' Cái') as soluong,concat(format(dongia,0),' VNĐ') as dongia,mota from laptop,hanglaptop,loailaptop where laptop.mahanglaptop = hanglaptop.mahanglaptop and laptop.maloailaptop = loailaptop.maloailaptop and laptop.Dongia >= ".$gia_tu." and laptop.Dongia <= ".$gia_den." limit $x,$sodong";
$kq1 = mysql_query($lenh1);
?>
<form id="search_form_1" name="search_form_1" method="post" action="index.php?act=timkiemtheogia" enctype="multipart/form-data" onsubmit="return  validForm()">
  <table width="550" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF99CC" bgcolor="#FFFF99" style="border-collapse:collapse">
    <tr>
      <td height="40" colspan="2" align="center" bgcolor="#FFFF66"><strong>TÌM KIẾM THEO GIÁ</strong></td>
    </tr>
    <tr>
      <td width="141" style="padding-left:20px">Giá từ: 
        <label for="ten"></label>        <label for="tim"></label></td>
      <td width="409" style="padding-left:20px"><label for="gia_tu"></label>
        <select name="gia_tu" id="gia_tu" style="width:110px">
         <?php
	  for($i = 500000;$i <= 20000000;$i+=500000)
	  {
		?>  
		   <option value='<?php echo $i;  ?>'<?php   if($_POST['gia_tu']==$i){?> selected="selected"<?php } ?>><?php  echo number_format($i,0,',','.');  ?></option>
       <?php
		  
	  }
	  
	  ?>
     
      </select>        <input type="submit" name="tim" id="tim" value="Tìm" onclick="kiemtra()" /></td>
    </tr>
    <tr>
      <td style="padding-left:20px">Giá đến: </td>
      <td style="padding-left:20px"><label for="gia_den"></label>
        <select name="gia_den" id="gia_den" style="width:110px">
        <?php
	  for($i = 500000;$i <= 20000000;$i+=500000)
	  {
		?>  
		   <option value='<?php echo $i;  ?>'<?php   if($_POST['gia_den']==$i){?> selected="selected"<?php } ?>><?php  echo number_format($i,0,',','.');  ?></option>
       <?php
		  
	  }
	  
	  ?>
      </select>        <label for="hang"></label></td>
    </tr>
    <tr>
      <td colspan="2" style="padding-left:20px"><?php if(isset($_POST["gia_tu"])&&isset($_POST["gia_den"]))echo $tb;   ?></td>
    </tr>
    <tr>
      <td colspan="2">
      <?php
	  if(isset($gia_tu)||isset($gia_den))
	  {
	  echo"<table width='100%' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#FF99CC' bgcolor='#FFFFCC' style='border-collapse:collapse'>
  <tr>
    <td height='40' colspan='2' align='center' bgcolor='#FFFF99'><strong>THÔNG TIN SẢN PHẨM</strong></td>
  </tr>";
  while($row = mysql_fetch_row($kq1))
  {
  $nd = str_replace($ten,'<span style="background:#FFFF00; color:#FF0000">'.$ten.'</span>',$row[6]);
    $th = str_replace($ten,'<span style="background:#FFFF00; color:#FF0000">'.$ten.'</span>',$row[2]);
  echo"<tr>
    <td width='150' id='noidung2'><img src='laptop/$row[0]' width='150' height='100' /></td>
    <td width='400' id = 'noidung' valign='top'><font color='#000066'><b>Tên laptop:</b></font> $row[1]<br><font color='#FF0000'>Hãng laptop:</font> $th<br><font color='#00FF00'>Loại laptop:</font> $row[3] - $nd - $row[5]<br><font color='#FF00FF'>Mô tả:</font><font color='#0000CC'> $row[6]</font></td>
  </tr>";
  }
echo"</table>";
	}  
	  ?>
      
      </td>
    </tr>
  </table>
  <p align="center">
<?php
 if(isset($gia_tu)||isset($gia_den))
{
for($i = 1; $i <= $sotrang; $i++)
{
	if($i == $p)
	{
		echo $i."&nbsp;";
	}
	else
	{
	?>
	<a href="index.php?act=timkiemtheogia&gia_tu=<?php  echo $gia_tu;   ?>&gia_den=<?php  echo $gia_den;   ?>&p=<?php echo $i;    ?>"><?php echo $i;    ?></a>
	<?php
	}
}
}

?>
</p>
</form>
</body>
</html>
